package com.quanxiaoha.weblog.admin.controller;

import com.quanxiaoha.weblog.admin.model.vo.image.DeleteImageReqVO;
import com.quanxiaoha.weblog.admin.service.AdminImageService;
import com.quanxiaoha.weblog.common.Response;
import com.quanxiaoha.weblog.common.aspect.ApiOperationLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminImageController {

    @Resource
    private AdminImageService adminImageService;

    @PostMapping("/image/list")
    @ApiOperationLog(description = "获取所有图片")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response<?> queryImageListRspVOList() {
        return Response.success(adminImageService.queryImageListRspVOList());
    }

    @PostMapping("/image/delete")
    @ApiOperationLog(description = "删除图片")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response<?> deleteImage(@RequestBody DeleteImageReqVO req) {
        adminImageService.deleteImage(req);
        return Response.success();
    }
}
